<script setup>
import api from "./api.js";
import CompanyEditDialog from "./CompanyEditDialog.vue";
import useDepartmentStore from "@/store/modules/department.js";

const store = useDepartmentStore();

const tableData = ref([])
const paging = reactive({
  total: 1,
  pageNum: 1,
  pageSize: 10,
})
const tableRef = ref()
const companyEditDialog = ref();


function handleCompany() {
  companyEditDialog.value.open();
}

const companyId = computed(()=> {
  return store.getCompanyId();
});

function getList() {

  if (!companyId.value) {
    return;
  }
  api.list(companyId.value).then(response => {
    tableData.value = response;

  }).catch(error => {
    console.log(error);
  });
}

watch(companyId, () => {
  getList();
})

</script>

<template>
  <div class="right-main" style="height: 100%;display: flex;flex-direction: column;">

    <div style="margin-bottom: 15px;">
      <el-button  @click="handleCompany">增加</el-button>
    </div>
    <vxe-table style="height: 100%;flex-grow: 1;"
        border="full"
        ref="tableRef"
        :column-config="{resizable: true}"
        :data="tableData">
      <vxe-column field="deptName" title="名称" tree-node></vxe-column>
      <vxe-column field="leader" title="负责人"></vxe-column>
    </vxe-table>

    <company-edit-dialog ref="companyEditDialog" @sub="getList"></company-edit-dialog>

  </div>
</template>

<style scoped lang="scss">
  .right-main {
    flex-grow: 1;
    box-sizing: border-box;
    padding: 15px;
    margin-left: 130px;
    width: calc(100% - 130px);
  }
</style>